package com.jeehentor.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeehentor.common.vo.Result;
import com.jeehentor.dto.DepartDTO;
import com.jeehentor.dto.IdsRequestDTO;
import com.jeehentor.dto.QueryDepartDTO;
import com.jeehentor.system.service.ISysDepartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 组织机构表 前端控制器
 * </p>
 *
 * @author wzd
 * @since 2024-04-17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/depart")
@Tag(name = "组织机构管理")
public class SysDepartController {

    private final ISysDepartService sysDepartService;

    @Operation(summary = "添加组织")
    @PostMapping("/addDepart")
    public Result<String> addMenu(@RequestBody DepartDTO departDTO){
        sysDepartService.addDepart(departDTO);
        return Result.ok("添加成功");
    }

    @Operation(summary = "查询组织")
    @PostMapping("/selectDepart")
    public Result<Page<DepartDTO>> selectDepart(@RequestBody QueryDepartDTO queryDepartDTO){
        Page<DepartDTO> departModelPage = sysDepartService.selectDepart(queryDepartDTO);
        return Result.OK(departModelPage);
    }

    @Operation(summary = "查询组织(无分页)")
    @PostMapping("/list")
    public Result<List<DepartDTO>> list(){
        List<DepartDTO> modelList = sysDepartService.selectList();
        return Result.OK(modelList);
    }

    @Operation(summary = "更新组织")
    @PostMapping("/updateDepart")
    public Result<String> updateDepart(@RequestBody DepartDTO departDTO){
        sysDepartService.updateDepart(departDTO);
        return Result.ok("更新成功");
    }

    @Operation(summary = "删除组织")
    @PostMapping("/deleteDepart")
    public Result<String> deleteDepart(@RequestBody IdsRequestDTO ids){
        sysDepartService.deleteDepart(ids);
        return Result.ok("删除成功");
    }
}
